package ibmetp.mis.tags;

import ibmetp.mis.dao.CommonDao;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

public class DeptStatisticsTag extends TagSupport  {
    
	@Override
	public int doEndTag() throws JspException {
		CommonDao cd=new CommonDao();
		Map<String,Integer> map=cd.getDeptStatics();
		
		JspWriter out = pageContext.getOut();

		double min = 0, max = 0;

		for (Integer d : map.values()) {
			min = Math.min(d, min);
			max = Math.max(d, max);
		}

		StringBuffer buffer = new StringBuffer();

		buffer.append("<table>");

		for (Entry<String, Integer> entry : map.entrySet()) {
			buffer.append("<tr>");
			buffer.append("<td><strong style=\'color:green;font:楷体;\'>" + entry.getKey() + "</strong></td>");
			buffer.append("<td><img src='../../style/images/vote.gif' height='10' width='");
			buffer.append((entry.getValue() - min) / (max - min + 1) * 200 + 50);
			buffer.append("' /><strong style=\'color:green;\'> " + entry.getValue() + "</strong></td>");
			buffer.append("</tr>");
		}

		buffer.append("</table>");

		try {
			out.write(buffer.toString());
		} catch (Exception e) {
		}

		return super.doEndTag();
	}
	
	

}
